package com.may.module.security.mapper;

import com.may.module.security.entity.PermissionEntity;
import com.may.module.security.entity.UserEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author May
 * @date 2021/08/03 13:53
 */
@Mapper
public interface UserMapper {

    /**
     * 根据用户名查询用户
     * @param username username
     * @return com.may.module.security.entity.UserEntity
     *
     * @author mayuanbao
     * @date 2021/08/03 16:34
     */
    @Select("select * from sys_user where username = #{username}")
    UserEntity findByUsername(@Param("username") String username);

    /**
     * 根据用户名查询权限
     * @param username username
     * @return java.util.List<com.may.module.security.entity.PermissionEntity>
     *
     * @author mayuanbao
     * @date 2021/08/03 16:35
     */
    @Select("SELECT sp.*\n" +
            "FROM sys_user user\n" +
            "         INNER JOIN sys_user_role sur ON user.id = sur.user_id\n" +
            "         INNER JOIN sys_role_permission srp ON sur.role_id = srp.role_id\n" +
            "         INNER JOIN sys_permission sp ON sp.id = srp.perm_id\n" +
            "WHERE user.username = #{username}")
    List<PermissionEntity> findPermissionByUsername(@Param("username") String username);
}
